/**
*********************************************************************************************************
*               Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
*********************************************************************************************************
* @file      rtl876x_i2c.h
* @brief
* @details
* @author
* @date
* @version
* *********************************************************************************************************
*/

#ifndef __RTL876X_I2C_H
#define __RTL876X_I2C_H

#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "rtl876x.h"
#include "rtl876x_bitfields.h"


typedef struct
{
    uint32_t I2C_ClockSpeed;      /*!< Specifies the clock frequency.
                                                This parameter must be set to a value lower than 400kHz */
    uint16_t I2C_AddressMode;     /*!< Specifies the I2C address mode.
                                                This parameter can be a value of @ref I2C_address_mode */

    uint16_t I2C_SlaveAddress;    /*!< Specifies the first device own address.
                                                This parameter can be a 7-bit or 10-bit address. */
    uint8_t I2C_SDA_Pin;
    uint8_t I2C_SCL_Pin;
    
    uint32_t xI2C_SDA_Pin;
    uint32_t xI2C_SCL_Pin;
    
    uint16_t delay;
    uint16_t busFreeTime;      /* bus free time between STOP and START*/
    bool busy_flag;
} GPIO_I2C_InitTypeDef;

typedef enum
{
    I2C_GPIO_Success,
    I2C_GPIO_BUSY,
    I2C_GPIO_BUS_ERROR,
    I2C_GPIO_TXDATA_NOACK,
    I2C_GPIO_ADDR_NOACK,
    I2C_GPIO_ERR_TIMEOUT,
    I2C_GPIO_LOCKED,
    I2C_GPIO_INVALUE,
} GPIO_I2C_Status;

void GPIO_I2C_DeInit(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct);

void GPIO_I2C_Init(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct);

void GPIO_I2C_StructInit(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct); 

GPIO_I2C_Status GPIO_I2C_MasterRead(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct, uint8_t *pBuf,
                                    uint16_t len);
GPIO_I2C_Status GPIO_I2C_MasterWrite(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct, uint8_t *pBuf,
                                     uint16_t len);
GPIO_I2C_Status GPIO_I2C_RepeatRead(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct, uint8_t *pWriteBuf,
                                    uint16_t Writelen,
                                    uint8_t *pReadBuf, uint16_t Readlen);

GPIO_I2C_Status GPIO_I2C_MasterRead_no_p(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct, uint8_t *pBuf,
                                    uint16_t len);
GPIO_I2C_Status GPIO_I2C_MasterWrite_no_p(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct, uint8_t *pBuf,
                                     uint16_t len);
GPIO_I2C_Status GPIO_I2C_SetSlaveAddr(GPIO_I2C_InitTypeDef *GPIO_I2C_InitStruct, uint8_t slave_addr);
#ifdef __cplusplus
}
#endif

#endif /*__RTL8762X_I2C_H*/
